/*
 * GLComponentDelegate.h  0.4.0 / Nov 28, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#ifndef GLCOMPONENTDELEGATE_H
#define GLCOMPONENTDELEGATE_H

#include "Cute4jOpenGL.h"

#include "ComponentDelegate.h"

// GLComponentDelegate Class. --------------------------------------------------

/*!
 * \brief GLComponent Delegate.
 *
 * \author Slobodan Vrkacevic
 * \version 0.4.0
 */
class CUTE4J_EXPORT GLComponentDelegate : public ComponentDelegate
{
  Q_OBJECT
protected:
  GLComponentDelegate(JNIEnv *env, jobject obj);
public: // native calls
  void updateGL(JNIEnv *env);
public: // native calls
  static void initialize(JNIEnv *env, jclass cls);
  static jlong newInstance(JNIEnv *env, jobject obj);
public:
  inline QGLWidget *qGLWidget() const;
protected:
  friend class QGLWidgetAdapter; // uses all protected methods
  inline void callInitializeGL();
  inline void callResizeGL(int width, int height);
  inline void callPaintGL();
private:
  static jmethodID sm_createGLMID;
  static jmethodID sm_initializeGLMID;
  static jmethodID sm_resizeGLMID;
  static jmethodID sm_paintGLMID;
};

// GLComponentDelegate :: Protected Inline Member Functions. -------------------

/*!
 * \brief Returns QGLWidget adaptee.
 *
 * \return QGLWidget adaptee
 */
inline QGLWidget *GLComponentDelegate::qGLWidget() const
{
  return static_cast<QGLWidget *>(qObject());
}

/*!
 * \brief Calls initializeGL method of the GLComponent java object.
 */
inline void GLComponentDelegate::callInitializeGL()
{
  jniObject()->callVoidMethod(sm_initializeGLMID);
}

/*!
 * \brief Calls resizeGL method of the GLComponent java object.
 *
 * \param width the width
 * \param height the height
 */
inline void GLComponentDelegate::callResizeGL(int width, int height)
{
  jniObject()->callVoidMethod(sm_resizeGLMID, width, height);
}

/*!
 * \brief Calls paintGL method of the GLComponent java object.
 */
inline void GLComponentDelegate::callPaintGL()
{
  jniObject()->callVoidMethod(sm_paintGLMID);
}

// Macro Definitions. ----------------------------------------------------------

#define GLCOMPONENT_DELEGATE (reinterpret_cast<GLComponentDelegate *>(delegate))

#endif // GLCOMPONENTDELEGATE_H
